package com.lbw.service.impl;

import com.lbw.feign.ProductFeignClient;
import com.lbw.order.entity.Order;
import com.lbw.product.entity.Product;
import com.lbw.service.IOrderService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Arrays;

@Service
@Slf4j
public class OrderServiceImpl implements IOrderService {

    @Resource
    private ProductFeignClient productFeignClient;

    /**
     * 创建订单
     *
     * @param productId
     * @param userId
     * @return
     */
    @Override
    public Order createOrder(Long productId, Long userId) {
        Product productByFeign = productFeignClient.getProductById(productId);
        log.info("调用feign查询到的商品数据：{}",productByFeign);
        Order order = new Order();
        order.setId(1L);
        order.setUserId(userId);
        order.setTotalAmount(new BigDecimal("0"));
        order.setNickName("LBW");
        order.setAddress("黑马");
        order.setProductList(Arrays.asList(productByFeign));
        return order;
    }
}
